<?php

namespace App\Services\User;

use App\Exceptions\BusinessException;
use App\Helpers\Enums\ResponseEnum;
use App\Models\User\User;
use App\Services\BaseService;

class UserService extends BaseService
{
    /**
     * 存储用户信息
     * @param array $param
     * @throws BusinessException
     */
    public function store(array $params)
    {
        $user = new User();
        $user->mobile = $params['mobile'];
        $user->password = bcrypt($params['password']);
        if (!$user->save()){
            $this->throwBusinessException(ResponseEnum::USER_SERVICE_REGISTER_ERROR);
        }
        // 记录用户注册日志
        $this->createActivityLog('user_register', $params, ResponseEnum::USER_SERVICE_REGISTER_SUCCESS[1]);
    }

    public function info(string $userId)
    {
        return User::query()->where('user_id', $userId)->first();
    }


}
